package net.zjitc.servlet;

import net.zjitc.domain.Category;
import net.zjitc.service.CategoryService;
import net.zjitc.service.impl.CategoryServiceImpl;
import net.zjitc.servlet.category.AllServlet;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

/**
 * 2 * @Author: 洪瑶
 * 3 * @Date: 2018/11/13 9:37
 * 4
 */
@WebServlet(name = "ApacheServlet",urlPatterns = "/apache")
public class ApacheServlet extends HttpServlet {
    Log log = LogFactory.getLog(AllServlet.class);
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        log.info("hahahahaha  info test ……");
        log.debug("hahahahaha  debug test ……");
        CategoryService service = new CategoryServiceImpl();
        try {
            List<Category>list = service.findAll();
            request.setAttribute("list",list);
            log.debug("hahahahaha  debug……"+list);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        request.getRequestDispatcher("common/category/category.jsp").forward(request,response);
    }
}
